package com.ly.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ly.beans.Users;
import com.ly.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Controller
public class UserController {

    @Autowired
    private UserService service;

    //列表
    @RequestMapping("list")
    public String list(@RequestParam(value = "pageNum",required = true,defaultValue = "1") Integer pageNum, Map<String,Object> map){
        PageHelper.startPage(pageNum,3);
        List<Users> list = service.getlist();
        PageInfo<Users> page = new PageInfo<>(list);
        map.put("list",list);
        map.put("page",page);
        return "list";
    }

    //批量删除
    @RequestMapping("dels")
    public String dels(int[] ids){
        System.out.println("批量删除"+ids);

        service.dels(ids);
        return "redirect:/list";
    }
    //单个删除
    @RequestMapping("del")
    public String dels(Integer id){
        System.out.println("删除"+id);
        service.del(id);
        return "redirect:/list";
    }
}
